using System;
using System.Drawing;

namespace PowerLanguage.Indicator
{
    public class Block_Trades_per_Bar : IndicatorObject
    {
        private VariableObject<Double> m_blocktrades;

        private VariableObject<int> m_barnum;

        private IPlotObject Plot1;

        public Block_Trades_per_Bar(object ctx) :
            base(ctx){
            datanum = 1;
            blocksize = 5000;
        }

        [Input]
        public double blocksize { get; set; }

        [Input]
        public double datanum { get; set; }

        protected override void Create(){
            m_blocktrades = new VariableObject<Double>(this);
            m_barnum = new VariableObject<int>(this);
            Plot1 =
                AddPlot(new PlotAttributes("BlockTrds", EPlotShapes.Histogram,
                                           Color.Blue, Color.Empty, 1, 0,
                                           true));
        }

        protected override void CalcBar(){
            if ((Bars.LastBarOnChart
                 && (Bars.Status != EBarState.Close))){
                if ((m_barnum.Value != Bars.CurrentBar)){
                    m_blocktrades.Value = 0;
                    m_barnum.Value = Bars.CurrentBar;
                }
                if (PublicFunctions.DoubleGreaterEquals(0, blocksize)){
                    m_blocktrades.Value = (m_blocktrades.Value + 1);
                }
                Plot1.Set(0, m_blocktrades.Value);
            }
        }
    }
}